use "C:\Users\jkbrueck\Documents\STATA\Fuel 4\US data\Calvin3_A_car.dta", clear

drop y1991-y2010 yy1991-yy2019 plane_model
rename ff2 ff 

gen retired = 0

replace retired = 1 if y2014 == "A" & (y2015 == "O" | y2015 == "D" | y2015 == "C" | y2015 == "X" | y2015 == "S")

replace retired = 1 if (y2015 == "A" & y2014 == "A") & ///
(y2016 == "O" | y2016 == "D" | y2016 == "C" | y2016 == "X" | y2016 == "S")

replace retired = 1 if (y2016 == "A" & y2015 == "A" & y2014 == "A") & ///
(y2017 == "O" | y2017 == "D" | y2017 == "C" | y2017 == "X" | y2017 == "S")

replace retired = 1 if (y2017 == "A" & y2016 == "A" & y2015 == "A" & y2014 == "A") & ///
(y2018 == "O" | y2018 == "D" | y2018 == "C" | y2018 == "X" | y2018 == "S")

replace retired = 1 if (y2018 == "A" & y2017 == "A" & y2016 == "A" & y2015 == "A" & y2014 == "A") & ///
(y2019 == "O" | y2019 == "D" | y2019 == "C" | y2019 == "X" | y2019 == "S")

keep if retired == 1

gen retyr = 0
replace retyr = 2015 if y2014 == "A" & (y2015 == "O" | y2015 == "D" | y2015 == "C" | y2015 == "X" | y2015 == "S")

replace retyr = 2016 if (y2015 == "A" & y2014 == "A") & ///
(y2016 == "O" | y2016 == "D" | y2016 == "C" | y2016 == "X" | y2016 == "S")

replace retyr = 2017 if (y2016 == "A" & y2015 == "A" & y2014 == "A") & ///
(y2017 == "O" | y2017 == "D" | y2017 == "C" | y2017 == "X" | y2017 == "S")

replace retyr = 2018 if (y2017 == "A" & y2016 == "A" & y2015 == "A" & y2014 == "A") & ///
(y2018 == "O" | y2018 == "D" | y2018 == "C" | y2018 == "X" | y2018 == "S")

replace retyr = 2019 if (y2018 == "A" & y2017 == "A" & y2016 == "A" & y2015 == "A" & y2014 == "A") & ///
(y2019 == "O" | y2019 == "D" | y2019 == "C" | y2019 == "X" | y2019 == "S")

gen scrap = 0
replace scrap = 1 if retyr == 2015 & y2015 == "S"
replace scrap = 1 if retyr == 2016 & y2016 == "S"
replace scrap = 1 if retyr == 2017 & y2017 == "S"
replace scrap = 1 if retyr == 2018 & y2018 == "S"
replace scrap = 1 if retyr == 2019 & y2019 == "S"

gen retnonscrap = " "
replace retnonscrap = y2015 if retyr == 2015
replace retnonscrap = y2016 if retyr == 2016
replace retnonscrap = y2017 if retyr == 2017
replace retnonscrap = y2018 if retyr == 2018
replace retnonscrap = y2019 if retyr == 2019

tab retnonscrap

gen age = retyr - ff

summarize scrap

sort airline type age retyr

save "C:\Users\jkbrueck\Documents\STATA\Fuel 4\US data\Calvin3_small.dta", replace




